//
//  BFSHCommitOrderViewController.m
//  BeautyFood
//
//  Created by imac on 2020/4/28.
//  Copyright © 2020 stoneobs. All rights reserved.
//

#import "THCommitOrderViewController.h"
#import "BFShCommitOrderItemView.h"
#import "STTools_AutoAddView.h"
#import "THMineScoreViewController.h"
@interface THCommitOrderViewController ()
@property(nonatomic, strong) NSMutableArray                     *itemsarray;/**<  */
@property(nonatomic, strong) STLabel                     *money_lable;/**<  */
@property(nonatomic, strong) THAddressModel                     *defultAddressModel;/**<  */

@property(nonatomic, strong) STButton                     *choseButton;/**<  */
@property(nonatomic, strong) STButton                     *scoreButton;/**<  */
@property(nonatomic, strong) STTools_AutoAddView                     *addView;/**<  */
@property(nonatomic, strong) NSString                     *all_post;/**<  */
@property(nonatomic, strong) NSString                     *current_score;/**<  */

@end

@implementation THCommitOrderViewController

- (void)setDefultAddressModel:(THAddressModel *)defultAddressModel{
    _defultAddressModel = defultAddressModel;
    [self stoneobs_ui_configSubView];
    self.money_lable.text = [NSString stringWithFormat:@"￥%0.2f",[self allPrice]];
}
#pragma mark --vc生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = self.tableView.backgroundColor;
    [THMineScoreViewController send_get_score_handle:^(NSString * _Nonnull score) {
        self.current_score = score;
    }];
    self.title = @"确认订单";
    self.tableView.contentInset = UIEdgeInsetsZero;
    self.tableView.frame = CGRectMake(0, TMUtils.stoneobs_fun_get_navgationBarBootom, STONEOBS_UI_UISCREEN_WIDTH, TMUtils.stoneobs_fun_get_tabBarTop - TMUtils.stoneobs_fun_get_navgationBarBootom - 0 - 60);

    [self stoneobs_fun_st_autoAdjustAllResponder];

    [self reloadData];
    // Do any additional setup after loading the view.
}
- (void)reloadData{
    [THUserDataController stoneobs_fun_send_get_user_defult_address_handle:^(THAddressModel * _Nonnull model) {
        _defultAddressModel = model;
        if (!model) {
            [self stoneobs_fun_st_showAlertTitle:@"您还没有添加地址" message:@"" leftTitle:@"取消" rightTitle:@"添加" block:^(NSString *name) {
                if ([name isEqualToString:@"添加"]) {
                    THAddressHomeViewController * vc = THAddressHomeViewController.new;
                    [self pushViewController:vc animated:YES];
                }
                if ([name isEqualToString:@"取消"]) {
                    [self.navigationController popViewControllerAnimated:YES];
                }
            }];
        }
        [self send_get_postage_request:^{
            self.defultAddressModel = model;
            [self configBootomView];
        }];

    }];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if (self.didLoad) {
        if (!self.defultAddressModel) {
            [self reloadData];
        }
    }
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
- (CGFloat)allPrice{
    CGFloat sum = 0;
    if (self.detailModel) {
        sum =  self.detailModel.cus_selected_spec_price.floatValue * self.detailModel.cus_selected_spec.cus_num + self.detailModel.cus_countPostage.floatValue;
    }else{
        for (BFShShopCarModel * model in self.dataSouce) {
            sum = model.goods_price* model.num + sum + model.cus_countPostage.floatValue;
        }
    }
    if (self.choseButton.selected) {
        sum = sum + 1;
    }
    if (self.scoreButton.selected) {
        NSInteger money = self.addView.textFiled.text.intValue *1;
        sum = sum - money;
    }
    sum = sum + self.all_post.floatValue;
    return sum;
}
- (CGFloat)basePrice{
    CGFloat sum = 0;
    if (self.detailModel) {
        sum =  self.detailModel.cus_selected_spec_price.floatValue * self.detailModel.cus_selected_spec.cus_num + self.detailModel.cus_countPostage.floatValue;
    }else{
        for (BFShShopCarModel * model in self.dataSouce) {
            sum = model.goods_price* model.num + sum + model.cus_countPostage.floatValue;
        }
    }
    return sum;
}
- (void)configBootomView{
    UIView * bootomView = [[UIView alloc] initWithFrame:CGRectMake(0, TMUtils.stoneobs_fun_get_tabBarTop, STONEOBS_UI_UISCREEN_WIDTH, 49 + 50)];
    [self.view addSubview:bootomView];
    bootomView.backgroundColor = UIColor.whiteColor;
    [bootomView stoneobs_fun_st_showTopShadow];
    __weak typeof(self) weakSelf =  self;
    ({
        STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH - 0, 44)
                                                                  title:@"加一元购买不满意免费退货邮费"
                                                             titleColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                              titleFont:15
                                                           cornerRadius:0
                                                        backgroundColor:self.tableView.backgroundColor
                                                        backgroundImage:nil
                                                                  image:[UIImage imageNamed:@"wgx"]];
        [stoneobs_ui_button setImage:[UIImage imageNamed:@"gx"] forState:UIControlStateSelected];
        stoneobs_ui_button.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        stoneobs_ui_button.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
//        [self.view addSubview:stoneobs_ui_button];
        [stoneobs_ui_button setClicAction:^(UIButton *sender) {
            sender.selected = !sender.selected;
            weakSelf.money_lable.text = [NSString stringWithFormat:@"￥%0.2f",[self allPrice]];
        }];
        self.choseButton = stoneobs_ui_button;
        stoneobs_ui_button.bottom = bootomView.top - 60;
        
//        if (self.dataSouce.count > 0) {
//            stoneobs_ui_button.bottom = bootomView.top - 0;
//        }else{
//            ({
//                UIView * scorlView = [self config_score_view];
//                [self.view addSubview:scorlView];
//                scorlView.bottom = bootomView.top;
//            });
//        }
//        购物车和直接购买都可以积分
        ({
            UIView * scorlView = [self config_score_view];
            [self.view addSubview:scorlView];
            scorlView.bottom = bootomView.top;
        });
    });

    STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(16, 0, 200, 49)
                                                            text:[NSString stringWithFormat:@"￥%0.2f",[self allPrice]]
                                                       textColor:WH_UICOLOR_FROM_RGBA(0xFF2F3D)
                                                            font:15
                                                     isSizetoFit:NO
                                                   textAlignment:NSTextAlignmentLeft];
    [bootomView addSubview:stoneobs_ui_label];
    self.money_lable = stoneobs_ui_label;

    STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(10, 0, 90, 30)
                                                              title:@"提交订单"
                                                         titleColor:UIColor.whiteColor
                                                          titleFont:13
                                                       cornerRadius:15
                                                    backgroundColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR
                                                    backgroundImage:nil
                                                              image:nil];
    stoneobs_ui_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    stoneobs_ui_button.centerY = 24.5;
    [bootomView addSubview:stoneobs_ui_button];
    stoneobs_ui_button.backgroundColor = [UIColor colorWithGradientStyle:UIGradientStyleTopToBottom withFrame:stoneobs_ui_button.bounds andColors:@[WH_UICOLOR_FROM_RGBA(0x56BD49),WH_UICOLOR_FROM_RGBA(0x25B13A)]];
    stoneobs_ui_button.right = STONEOBS_UI_UISCREEN_WIDTH - 10;
    [stoneobs_ui_button setClicAction:^(UIButton *sender) {
        if (!weakSelf.defultAddressModel) {
            [SVProgressHUD showInfoWithStatus:@"请选择地址"];
            return;
        }
        if (weakSelf.dataSouce.count > 0) {
            //购物车结算
            [weakSelf stoneobs_fun_send_commit_shopcar_request];
        }else{
            [weakSelf stoneobs_fun_send_commit_good_detail_request];
        }
        
    }];
}
- (UIView*)config_score_view{
    if (!self.current_score) {
        [THMineScoreViewController send_get_score_handle:^(NSString * _Nonnull score) {
            self.current_score = score;
        }];
    }
    __weak typeof(self) weakSelf =  self;
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, 60)];
    view.backgroundColor = UIColor.whiteColor;
    ({
        STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH - 0, 40)
                                                                  title:@""
                                                             titleColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                              titleFont:15
                                                           cornerRadius:0
                                                        backgroundColor:nil
                                                        backgroundImage:nil
                                                                  image:[UIImage imageNamed:@"wgx"]];
        [stoneobs_ui_button setImage:[UIImage imageNamed:@"gx"] forState:UIControlStateSelected];
        stoneobs_ui_button.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        stoneobs_ui_button.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
        [view addSubview:stoneobs_ui_button];
        [stoneobs_ui_button setClicAction:^(UIButton *sender) {
            if (1 * weakSelf.addView.textFiled.text.intValue >= weakSelf.current_score.floatValue) {
                sender.selected = NO;
                [SVProgressHUD showErrorWithStatus:@"积分不足"];
                return;
            }
            sender.selected = !sender.selected;
            weakSelf.money_lable.text = [NSString stringWithFormat:@"￥%0.2f",[weakSelf allPrice]];
        }];
        self.scoreButton = stoneobs_ui_button;
        
        self.addView = [[STTools_AutoAddView alloc] initWithFrame:CGRectMake(60, 0, 120, 30)];
        self.addView.textFiled.userInteractionEnabled = YES;
        [self stoneobs_fun_st_autoAdjustAllResponder];
        self.addView.centerY = 20;
        [self.addView setAutoaddViewWillChangeHandle:^BOOL(STTools_AutoAddView *autoAddView, NSString *willChangeText) {
            if (willChangeText.intValue * 1 > weakSelf.current_score.intValue) {
                [SVProgressHUD showErrorWithStatus:@"积分不足"];
                return NO;
            }
            if (willChangeText.intValue * 1 >= [self basePrice]) {
                [SVProgressHUD showErrorWithStatus:@"使用积分兑换不能大于等于原价哦"];
                return NO;
            }
            if (willChangeText.intValue <= 0 ) {
                [SVProgressHUD showErrorWithStatus:@"使用积分必须大于0哦"];
                return NO;
            }
            return YES;
        }];
        [self.addView setAutoaddViewDidChangeHandle:^(STTools_AutoAddView *autoAddView, NSString *didChangeText) {
            weakSelf.money_lable.text = [NSString stringWithFormat:@"￥%0.2f",[weakSelf allPrice]];
        }];
        [self.scoreButton addSubview:self.addView];
        [self.addView stbw_setBorderWith:2 borderColor:STONEOBS_UI_FIRST_TEXT_COLOR cornerRadius:15];
        NSString * base_num = @"1000";
        STLabel * num_label = [[STLabel alloc] initWithFrame:CGRectMake(self.addView.right+10, 0, UISCREEN_WIDTH - self.addView.right - 20, 30)
                                                                text:[NSString stringWithFormat:@"X%@",base_num]
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:15
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentRight];
//        [self.scoreButton addSubview:num_label];
        
        
        STLabel * s_label = [[STLabel alloc] initWithFrame:CGRectMake(10, self.scoreButton.bottom, UISCREEN_WIDTH - 20, 30)
                                                                text:[NSString stringWithFormat:@"当前积分%@(1积分等于1元 必须整1元使用)",weakSelf.current_score]
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:12
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [view addSubview:s_label];

        
    });
    return view;
}
#pragma mark --configSubView
- (void)stoneobs_ui_configSubView{

    UIView * header = [[UIView alloc] initWithFrame:STONEOBS_UI_UISCREEN_FRAME];
    header.backgroundColor = UIColor.whiteColor;
    CGFloat top = 15;
    __weak typeof(self) weakSelf =  self;

    
    ({
        BOOL hasAdd = self.defultAddressModel;

        if (hasAdd) {
            STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(15, top, STONEOBS_UI_UISCREEN_WIDTH - 30, 30)
                                                                      title:[NSString stringWithFormat:@"%@  %@",self.defultAddressModel.name,self.defultAddressModel.phone]
                                                                 titleColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                  titleFont:15
                                                               cornerRadius:0
                                                            backgroundColor:nil
                                                            backgroundImage:nil
                                                                      image:nil];
            [header addSubview:stoneobs_ui_button];
            [stoneobs_ui_button setAttributedTitle:[stoneobs_ui_button.currentTitle stoneobs_fun_st_convertAttributeStringWithKeyWord:@"" attributes:@{NSForegroundColorAttributeName:STONEOBS_UI_THIRD_TEXT_COLOR,NSFontAttributeName:[UIFont systemFontOfSize:13]}] forState:UIControlStateNormal];
            
            NSString * address = [NSString stringWithFormat:@"%@%@%@\n%@",self.defultAddressModel.p_name,self.defultAddressModel.c_name,
                                  self.defultAddressModel.d_name,self.defultAddressModel.detail];
            STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, stoneobs_ui_button.bottom + 10, stoneobs_ui_button.width - 40, 30)
                                                                    text:address
                                                               textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                    font:15
                                                             isSizetoFit:NO
                                                           textAlignment:NSTextAlignmentLeft];
            [header addSubview:stoneobs_ui_label];;
            stoneobs_ui_label.font = [UIFont fontWithName:STONEOBS_UI_FONT_CU_NAME size:17];
            [NSString stoneobs_fun_lableAutoAdjustheightWithLabel:stoneobs_ui_label];
            top = stoneobs_ui_label.bottom  +20;
            
            UIImageView * stoneobs_ui_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 7, 12)];
            stoneobs_ui_imageView.image = [UIImage imageNamed:@"圆角矩形580"];
            [header addSubview:stoneobs_ui_imageView];
            stoneobs_ui_imageView.centerY = stoneobs_ui_label.centerY;
            stoneobs_ui_imageView.right = UISCREEN_WIDTH - 15;
            
            UITapGestureRecognizer * tap = [UITapGestureRecognizer.alloc initWithActionBlock:^(id  _Nonnull sender) {
                THAddressHomeViewController * vc = THAddressHomeViewController.new;
                [vc setDidSlectedAddressModel:^(THAddressModel * _Nonnull model) {
                    [self send_get_postage_request:^{
                        weakSelf.defultAddressModel = model;
                    }];
                   
                    
                }];
                [weakSelf pushViewController:vc animated:YES];
            }];
            stoneobs_ui_label.userInteractionEnabled = YES;
            [stoneobs_ui_label addGestureRecognizer:tap];
        }else{
            STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(15, top, STONEOBS_UI_UISCREEN_WIDTH - 30, 30)
                                                                      title:@"暂无地址，快去添加吧"
                                                                 titleColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                  titleFont:15
                                                               cornerRadius:0
                                                            backgroundColor:nil
                                                            backgroundImage:nil
                                                                      image:nil];
            [header addSubview:stoneobs_ui_button];
            [stoneobs_ui_button setClicAction:^(UIButton *sender) {
                THAddressHomeViewController * vc = THAddressHomeViewController.new;
                [vc setDidSlectedAddressModel:^(THAddressModel * _Nonnull model) {
                    weakSelf.defultAddressModel = model;
                    [weakSelf stoneobs_ui_configSubView];
                }];
                [weakSelf pushViewController:vc animated:YES];
            }];
            stoneobs_ui_button.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
            top = stoneobs_ui_button.bottom + 10;
            
            
            UIImageView * stoneobs_ui_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 7, 12)];
            stoneobs_ui_imageView.image = [UIImage imageNamed:@"圆角矩形580"];
            [header addSubview:stoneobs_ui_imageView];
            stoneobs_ui_imageView.centerY = stoneobs_ui_button.centerY;
            stoneobs_ui_imageView.right = UISCREEN_WIDTH - 15;

            
        }
        
        
    });
    
    ({
        UIImageView * stoneobs_ui_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(6, top, UISCREEN_WIDTH-12, 4.5)];
        stoneobs_ui_imageView.image = [UIImage imageNamed:@"条纹"];
        [header addSubview:stoneobs_ui_imageView];
        top = stoneobs_ui_imageView.bottom;
    });
    
    ({
        UIView * stoneobs_ui_line = [[UIView alloc] initWithFrame:CGRectMake(0, top, STONEOBS_UI_UISCREEN_WIDTH, 20)];
        stoneobs_ui_line.backgroundColor = self.tableView.backgroundColor;
        [header addSubview:stoneobs_ui_line];
        top = stoneobs_ui_line.bottom;
        [stoneobs_ui_line stoneobs_fun_stoneobs_fun_st_showRoundLayer];
    });
    
    self.itemsarray = NSMutableArray.new;
    if (self.detailModel) {
        BFShCommitOrderItemView * view = [[BFShCommitOrderItemView alloc] initWithFrame:STONEOBS_UI_UISCREEN_FRAME];
        view.detailModel = self.detailModel;
        view.top = top;
        top = view.bottom;
        [header addSubview:view];
        [self.itemsarray addObject:view];
        view.backgroundColor = UIColor.whiteColor;
        view.layer.cornerRadius = 10;
        view.clipsToBounds = YES;
        ({
            UIView * stoneobs_ui_line = [[UIView alloc] initWithFrame:CGRectMake(0, top, STONEOBS_UI_UISCREEN_WIDTH, 20)];
            stoneobs_ui_line.backgroundColor = self.tableView.backgroundColor;
            [header addSubview:stoneobs_ui_line];
            top = stoneobs_ui_line.bottom;
        });
        
        ({
            NSString * post = @"包邮";
            if (self.all_post.floatValue > 0) {
                post = self.all_post;
            }
            STButton * button = [self viewFormLeftTitle:@"配送邮费" value:post];
            button.top = top;
            top = button.bottom;
            [header addSubview:button];
        });
        
    }else{
        for (BFShShopCarModel * model in self.dataSouce) {
            NSInteger index = [self.dataSouce indexOfObject:model];
            BFShCommitOrderItemView * view = [[BFShCommitOrderItemView alloc] initWithFrame:STONEOBS_UI_UISCREEN_FRAME];
            view.model = model;
            view.top = top;
            top = view.bottom;
            [header addSubview:view];
            [self.itemsarray addObject:view];
            view.backgroundColor = UIColor.whiteColor;
            view.layer.cornerRadius = 10;
            view.clipsToBounds = YES;
            ({
                UIView * stoneobs_ui_line = [[UIView alloc] initWithFrame:CGRectMake(0, top, STONEOBS_UI_UISCREEN_WIDTH, 20)];
                stoneobs_ui_line.backgroundColor = self.tableView.backgroundColor;
                [header addSubview:stoneobs_ui_line];
                top = stoneobs_ui_line.bottom;
            });
            
            
                ({
                    NSString * post = @"包邮";
                    if (self.all_post.floatValue > 0) {
                        post = self.all_post;
                    }
                    STButton * button = [self viewFormLeftTitle:@"配送邮费" value:post];
                    button.top = top;
                    top = button.bottom;
                    [header addSubview:button];
                });
        }
    }
    


//    ({
//        UIView * stoneobs_ui_line = [[UIView alloc] initWithFrame:CGRectMake(0, top, STONEOBS_UI_UISCREEN_WIDTH, 5)];
//        stoneobs_ui_line.backgroundColor = self.tableView.backgroundColor;
//        [header addSubview:stoneobs_ui_line];
//        top = stoneobs_ui_line.bottom;
//    });
//
//    ({
//
//        STButton * button = [self viewFormLeftTitle:@"配送时间" value:@"sss"];
//        button.top = top;
//        top = button.bottom;
//        [header addSubview:button];
//    });
//
//
//
//    ({
//        STButton * button = [self viewFormLeftTitle:@"配送" value:@""];
//        button.top = top;
//        top = button.bottom;
//        [header addSubview:button];
//    });
//    ({
//        STButton * button = [self viewFormLeftTitle:@"售后" value:@"dsd"];
//        button.top = top;
//        top = button.bottom;
//        [header addSubview:button];
//    });
//
//
//    ({
//        UIView * stoneobs_ui_line = [[UIView alloc] initWithFrame:CGRectMake(0, top, STONEOBS_UI_UISCREEN_WIDTH, 5)];
//        stoneobs_ui_line.backgroundColor = self.tableView.backgroundColor;
//        [header addSubview:stoneobs_ui_line];
//        top = stoneobs_ui_line.bottom;
//    });
//
//    ({
//
//        STButton * button = [self viewFormLeftTitle:@"商品金额" value:[NSString stringWithFormat:@"￥%0.2f",[self allPrice]]];
//        button.top = top;
//        top = button.bottom;
//        [header addSubview:button];
//    });
     self.money_lable.text = [NSString stringWithFormat:@"￥%0.2f",[self allPrice]];
    
    
    
    header.height = top;
    self.tableView.tableHeaderView = header;
}

- (STButton*)viewFormLeftTitle:(NSString*)leftTitle value:(NSString*)value{
    STButton * view  = [[STButton alloc] initWithFrame:CGRectMake(0, 0, STONEOBS_UI_UISCREEN_WIDTH, 44)
                                                 title:nil
                                            titleColor:nil
                                             titleFont:0
                                          cornerRadius:0
                                       backgroundColor:nil
                                       backgroundImage:nil
                                                 image:nil];
    
    
    STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(17, 0, 120, view.height)
                                                            text:leftTitle
                                                       textColor:STMC_UICOLOR_FROM_RGBA(0xABABAB)
                                                            font:14
                                                     isSizetoFit:NO
                                                   textAlignment:NSTextAlignmentLeft];
    [view addSubview:stoneobs_ui_label];
    
    
    STLabel * stoneobs_ui_s_label = [[STLabel alloc] initWithFrame:CGRectMake(stoneobs_ui_label.right, 0, STONEOBS_UI_UISCREEN_WIDTH -stoneobs_ui_label.right - 20 , view.height)
                                                              text:value
                                                         textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                              font:14
                                                       isSizetoFit:NO
                                                     textAlignment:NSTextAlignmentRight];
    [view addSubview:stoneobs_ui_s_label];
    [NSString stoneobs_fun_lableAutoAdjustheightWithLabel:stoneobs_ui_s_label];
    if (stoneobs_ui_s_label.height < view.height) {
        stoneobs_ui_s_label.height = view.height;
    }else{
        view.height = stoneobs_ui_s_label.height + 20;
    }
    stoneobs_ui_label.centerY = view.height/2;
    stoneobs_ui_s_label.centerY = view.height/2;
    stoneobs_ui_s_label.tag = 10001;
    UIView * stoneobs_ui_line = [[UIView alloc] initWithFrame:CGRectMake(17, view.height - 0.5, STONEOBS_UI_UISCREEN_WIDTH, 5)];
    stoneobs_ui_line.backgroundColor = self.tableView.backgroundColor;
    [view addSubview:stoneobs_ui_line];
    __weak typeof(self) weakSelf =  self;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
  
    }];
    view.userInteractionEnabled = YES;
    [view addGestureRecognizer:tap];
    return view;
    
}

#pragma mark --stoneobs_net netWork Method
- (void)stoneobs_fun_send_commit_shopcar_request{
    NSMutableArray * ids = NSMutableArray.new;
    NSMutableDictionary * remardDic = NSMutableDictionary.new;
    for (BFShCommitOrderItemView * view in self.itemsarray) {
        [remardDic setObject:view.textView.text.length?view.textView.text:@"" forKey:view.model.s_id];
        [ids addObject:view.model.s_id];
    }
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * stoneobs_net_param_dic = [NSMutableDictionary new];
    NSString * stoneobs_net_user_id = [STTools_UserManger defult].stoneobs_fun_get_loginedUser.uid.description;
    NSString * stoneobs_net_user_token = STTools_UserManger.defult.stoneobs_fun_get_loginedUser.token;
    if (stoneobs_net_user_id.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_id forKey:@"uid"];
    }
    if (stoneobs_net_user_token.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_token forKey:@"token"];
    }
    NSString * ids_string = [ids componentsJoinedByString:@","];
    if (ids_string.length) {
        [stoneobs_net_param_dic setObject:ids_string forKey:@"id"];
    }
    [stoneobs_net_param_dic setObject:self.defultAddressModel.a_id forKey:@"address_id"];
    [stoneobs_net_param_dic setObject:remardDic.mj_JSONString forKey:@"remark"];
    NSString * stoneobs_net_net_url = [NSString stringWithFormat:@"%@%@",RELEASE_SERVER_URL_HEADER,@"v1/goods/carOrder"];
    if (self.choseButton.selected) {
        [stoneobs_net_param_dic setObject:@"1" forKey:@"is_safe"];
    }else{
        [stoneobs_net_param_dic setObject:@"0" forKey:@"is_safe"];
    }
    if (self.scoreButton.selected) {
        NSInteger integral = self.addView.textFiled.text.intValue * 1;
        [stoneobs_net_param_dic setObject:@(integral) forKey:@"integral"];
    }
    DDLogInfo(@"url:%@",stoneobs_net_net_url);
    DDLogInfo(@"param:%@",stoneobs_net_param_dic);
    [[STTools_NetWrokManger defaultClient] stoneobs_fun_requestWithPath:stoneobs_net_net_url
                                                                 method:STHttpRequestType_stoneobs_enumPost
                                                             parameters:stoneobs_net_param_dic
                                                                success:^(NSURLSessionDataTask *operation, id responseObject) {
        [SVProgressHUD dismiss];
        NSDictionary * stoneobs_net_model_dic = [responseObject valueForKey:@"data"];
        BOOL is_pay = [stoneobs_net_model_dic[@"is_pay"] boolValue];
        NSString * oid = [stoneobs_net_model_dic[@"order_id"] description];
        CGFloat pay_money = [stoneobs_net_model_dic[@"pay_money"] floatValue];
        THZhiFuViewController * vc = THZhiFuViewController.new;
        vc.order_id = oid;
        vc.pay_money = [NSString stringWithFormat:@"%0.2f",[self allPrice]];
        [self pushViewController:vc animated:1];
        [SVProgressHUD showSuccessWithStatus:@"下单成功"];
        [BFShShopCarDataController stoneobs_fun_update_shopcarcount_ifNeed];
        // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
        DDLogInfo(@"%@请求成功:resp\n%@",stoneobs_net_net_url,responseObject);
        
        
    } failure:^(NSString *stateCode, STTools_Error *error,NSError *originError) {
        [SVProgressHUD dismiss];
        [SVProgressHUD showErrorWithStatus:error.desc];
        DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                   stoneobs_net_net_url,stoneobs_net_param_dic,error.desc,error.code);
    }];
}
- (void)stoneobs_fun_send_commit_good_detail_request{

    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * stoneobs_net_param_dic = [NSMutableDictionary new];
    NSString * stoneobs_net_user_id = [STTools_UserManger defult].stoneobs_fun_get_loginedUser.uid.description;
    NSString * stoneobs_net_user_token = STTools_UserManger.defult.stoneobs_fun_get_loginedUser.token;
    if (stoneobs_net_user_id.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_id forKey:@"uid"];
    }
    if (stoneobs_net_user_token.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_token forKey:@"token"];
    }
    [stoneobs_net_param_dic setObject:self.detailModel.g_id forKey:@"goods_id"];
    [stoneobs_net_param_dic setObject:self.detailModel.g_id forKey:@"id"];
    if (self.detailModel.cus_selected_spec) {
       [stoneobs_net_param_dic setObject:@(self.detailModel.cus_selected_spec.cus_num) forKey:@"num"];
       [stoneobs_net_param_dic setObject:self.detailModel.cus_selected_spec.s_id forKey:@"spec_id"];
    }else{
        [stoneobs_net_param_dic setObject:@"1" forKey:@"num"];
    }
    if (self.detailModel.cus_type_selcted.length) {
        [stoneobs_net_param_dic setObject:self.detailModel.cus_type_selcted forKey:@"type_name"];
    }

    if (self.detailModel.is_pt) {
        if (!self.detailModel.cus_pt_mine_buy) {
            [stoneobs_net_param_dic setObject:@"1" forKey:@"is_pt"];
        }
        
        if (self.is_pt_and_i_create) {
            
        }else{
           [stoneobs_net_param_dic setObject:self.detailModel.cus_selected_group.group_id forKey:@"order_group_id"];
        }
    }

    [stoneobs_net_param_dic setObject:self.defultAddressModel.a_id forKey:@"address_id"];
    BFShCommitOrderItemView * view = self.itemsarray.firstObject;
    if (view.textView.text.length) {
        [stoneobs_net_param_dic setObject:view.textView.text forKey:@"remark"];
    }else{
        [stoneobs_net_param_dic setObject:@"" forKey:@"remark"];
    }
    
    if (self.choseButton.selected) {
        [stoneobs_net_param_dic setObject:@"1" forKey:@"is_safe"];
    }else{
        [stoneobs_net_param_dic setObject:@"0" forKey:@"is_safe"];
    }
    if (self.scoreButton.selected) {
        NSInteger integral = self.addView.textFiled.text.intValue * 1;
        [stoneobs_net_param_dic setObject:@(integral) forKey:@"integral"];
    }
    NSString * stoneobs_net_net_url = [NSString stringWithFormat:@"%@%@",RELEASE_SERVER_URL_HEADER,@"v1/goods/makeOrder"];
    DDLogInfo(@"url:%@",stoneobs_net_net_url);
    DDLogInfo(@"param:%@",stoneobs_net_param_dic);
    [[STTools_NetWrokManger defaultClient] stoneobs_fun_requestWithPath:stoneobs_net_net_url
                                                                 method:STHttpRequestType_stoneobs_enumPost
                                                             parameters:stoneobs_net_param_dic
                                                                success:^(NSURLSessionDataTask *operation, id responseObject) {
        [SVProgressHUD dismiss];
        NSDictionary * stoneobs_net_model_dic = [responseObject valueForKey:@"data"];
        BOOL is_pay = [stoneobs_net_model_dic[@"is_pay"] boolValue];
        NSString * oid = [stoneobs_net_model_dic[@"order_id"] description];
        CGFloat pay_money = [stoneobs_net_model_dic[@"pay_money"] floatValue];
        THZhiFuViewController * vc = THZhiFuViewController.new;
        vc.order_id = oid;
        vc.pay_money = [NSString stringWithFormat:@"%0.2f",[self allPrice]];
        [self pushViewController:vc animated:1];
        [SVProgressHUD showSuccessWithStatus:@"下单成功"];
        [BFShShopCarDataController stoneobs_fun_update_shopcarcount_ifNeed];
        // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
        DDLogInfo(@"%@请求成功:resp\n%@",stoneobs_net_net_url,responseObject);
        
        
    } failure:^(NSString *stateCode, STTools_Error *error,NSError *originError) {
        [SVProgressHUD dismiss];
        [SVProgressHUD showErrorWithStatus:error.desc];
        DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                   stoneobs_net_net_url,stoneobs_net_param_dic,error.desc,error.code);
    }];
}
- (void)send_get_postage_request:(void(^)(void))handle{
    NSMutableDictionary * stoneobs_net_param_dic = [NSMutableDictionary new];
    NSString * stoneobs_net_user_id = [STTools_UserManger defult].stoneobs_fun_get_loginedUser.uid.description;
    NSString * stoneobs_net_user_token = STTools_UserManger.defult.stoneobs_fun_get_loginedUser.token;
    if (stoneobs_net_user_id.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_id forKey:@"uid"];
    }
    if (stoneobs_net_user_token.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_token forKey:@"token"];
    }
    if (self.defultAddressModel.a_id.length) {
        [stoneobs_net_param_dic setObject:self.defultAddressModel.a_id forKey:@"id"];
    }else{
        return;
    }
    if (self.detailModel.g_id.length) {
        if (self.detailModel.cus_selected_spec) {
            [stoneobs_net_param_dic setObject:self.detailModel.cus_selected_spec.goods_id forKey:@"goods_id"];
            [stoneobs_net_param_dic setObject:@(self.detailModel.cus_selected_spec.cus_num) forKey:@"num"];
            [stoneobs_net_param_dic setObject:self.detailModel.cus_selected_spec.s_id forKey:@"spec_id"];
        }

    }else{
        NSMutableArray * ids = NSMutableArray.new;
        NSMutableArray * nums = NSMutableArray.new;
        for (BFShShopCarModel * model in self.dataSouce) {
            [ids addObject:model.s_id];
            [nums addObject:@(model.num)];
        }
        [stoneobs_net_param_dic setObject:[ids componentsJoinedByString:@","] forKey:@"ids"];
        [stoneobs_net_param_dic setObject:[nums componentsJoinedByString:@","]  forKey:@"nums"];
    }
    NSString * stoneobs_net_net_url = [NSString stringWithFormat:@"%@%@",RELEASE_SERVER_URL_HEADER,@"v1/goods/countPostage"];
    DDLogInfo(@"url:%@",stoneobs_net_net_url);
    DDLogInfo(@"param:%@",stoneobs_net_param_dic);
    [[STTools_NetWrokManger defaultClient] stoneobs_fun_requestWithPath:stoneobs_net_net_url
                                                                 method:STHttpRequestType_stoneobs_enumGet
                                                             parameters:stoneobs_net_param_dic
                                                                success:^(NSURLSessionDataTask *operation, id responseObject) {
        [SVProgressHUD dismiss];
        NSString * value = [[responseObject valueForKey:@"data"] description];
        self.all_post = value;
        if (handle) {
            handle();
        }
        // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
        DDLogInfo(@"%@请求成功:resp\n%@",stoneobs_net_net_url,responseObject);
        
        
    } failure:^(NSString *stateCode, STTools_Error *error,NSError *originError) {
        [SVProgressHUD dismiss];
        [SVProgressHUD showErrorWithStatus:error.desc];
        DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                   stoneobs_net_net_url,stoneobs_net_param_dic,error.desc,error.code);
    }];
}
@end
